package edu.pitt.dbmi.odie.gapp.gwt.model;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

import edu.pitt.dbmi.odie.gapp.gwt.client.dao.ODIE_DaoDocument;
import edu.upmc.opi.caBIG.common.CaBIG_UUIdGenerator;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class ODIE_Document {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key id;

	@Persistent
	private String odieId;

	@Persistent
	private String odieAnalysisId;

	@Persistent
	private String title;

	@Persistent
	private String atomId;

	@Persistent
	private String rawId;

	@Persistent
	private String documentStatus;

	@Persistent
	private Integer currentLineOffset;

	@Persistent
	private Integer currentAnnotationOffset;
	
	@Persistent
	private Integer numberOfLines;
	
	@Persistent
	private boolean isSelected;

	public ODIE_Document() {
		this.odieId = CaBIG_UUIdGenerator.getUUID();
		this.isSelected = false ;
	}

	public ODIE_Document(String odieAnalysisId, String title, String atomId,
			String rawId) {
		this.odieAnalysisId = odieAnalysisId;
		this.title = title;
		this.atomId = atomId;
		this.rawId = rawId;
	}

	public String getId() {
		return this.odieId;
	}
	
	public String getOdieId() {
		return this.odieId;
	}

	public void setOdieId(String odieId) {
		this.odieId = odieId;
	}

	public String getOdieAnalysisId() {
		return odieAnalysisId;
	}

	public void setOdieAnalysisId(String odieAnalysisId) {
		this.odieAnalysisId = odieAnalysisId;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getAtomId() {
		return atomId;
	}

	public void setAtomId(String atomId) {
		this.atomId = atomId;
	}

	public String getRawId() {
		return rawId;
	}

	public void setRawId(String rawId) {
		this.rawId = rawId;
	}

	public String getDocumentStatus() {
		return documentStatus;
	}

	public void setDocumentStatus(String documentStatus) {
		this.documentStatus = documentStatus;
	}

	public Integer getCurrentLineOffset() {
		return currentLineOffset;
	}

	public void setCurrentLineOffset(Integer currentLineOffset) {
		this.currentLineOffset = currentLineOffset;
	}

	public Integer getCurrentAnnotationOffset() {
		return currentAnnotationOffset;
	}

	public void setCurrentAnnotationOffset(Integer currentAnnotationOffset) {
		this.currentAnnotationOffset = currentAnnotationOffset;
	}

	public Integer getNumberOfLines() {
		return numberOfLines;
	}

	public void setNumberOfLines(Integer numberOfLines) {
		this.numberOfLines = numberOfLines;
	}
	
	public boolean isSelected() {
		return isSelected;
	}

	public void setSelected(boolean isSelected) {
		this.isSelected = isSelected;
	}
	
	public ODIE_DaoDocument convertToClientSideRecord() {
		ODIE_DaoDocument result = new ODIE_DaoDocument() ;
		result.setOdieId(this.odieId) ;
		result.setOdieAnalysisId(this.odieAnalysisId) ;
		result.setRawId(this.rawId) ;
		result.setTitle(title) ;
		result.setDocumentStatus(this.documentStatus) ;
		result.setSelected(this.isSelected) ;
		return result ;
	}

	public String toXml() {
		StringBuffer sb = new StringBuffer();
		if (id != null) {
			sb.append("<document>");
			sb.append("<id>" + getOdieId() + "</id>");
			sb.append("<odieAnalysisId>"+getOdieAnalysisId()+"</odieAnalysisId>") ;
			sb.append("<rawId>" + getRawId() + "</rawId>");
			sb.append("<title>" + getTitle() + "</title>");
			sb.append("<documentStatus>" + getDocumentStatus()
					+ "</documentStatus>");
			sb.append("<isSelected>" + isSelected() + "</isSelected>") ;
			sb.append("</document>");
		}
		return sb.toString();
	}

}
